<?php

namespace Zhifubao;


use Zhifubao\Request\AccountBookCreateRequest;
use Zhifubao\Request\AccountBookNotifySubscribe;
use Zhifubao\Request\AccountBookQueryRequest;
use Zhifubao\Request\AccountBookRechargeQueryRequest;
use Zhifubao\Request\AccountBookRechargeRequest;
use Zhifubao\Request\AccountBookSignRequest;
use Zhifubao\Request\AccountQueryRequest;
use Zhifubao\Request\AlipayFundTransUniTransferRequest;

class AccountBookClient extends Client
{


    public function create()
    {
        $request = new AccountBookCreateRequest();

        //{"alipay_fund_accountbook_create_response":{"code":"10000","msg":"Success","account_book_id":"2088610021182085","ext_card_info":{"bank_acc_name":"支付宝（中国）网络技术有限公司","card_bank":"支付机构备付金集中存管账户","card_branch":"支付宝-备付金账户","card_deposit":"991290000015","card_location":"上海市-上海市","card_no":"2088880800281045680","status":"A"}},"alipay_cert_sn":"af4413c2e7da2680854783d0b5128cde","sign":"EhcU/qeA74R1YAZoLG3brdUIfl88jyfor4OPJqPndZBCHp6UGGQQzfn0qFIxyDICt8AQ0sMAZ4FqliIQVgxQ2c8MCnA9ephlGcyGSRLbjXE9eI6oGJX7x4/Xs6WagPRRgFT8ShIGagRgStAsIrlHbfkYaUyEGzTnWMBU1/9hMMtWIL1RH06WNgxfWpmE4l6b+Ccd5VGH6r48QOud2tBiJbqZooBHNNUpJJdZhtPErO2j9hnRrmYtr+YT9XDafTCY2bQR7I4NlbcNuOM3agG8IK3xxsLFnmjcNdqsLVwf9sk+QKdylL6RqLZtZ+XcReVN6GTaGXGg9r5XiiNxP+4n3A=="}
        $request->setBizContent(json_encode([
            'merchant_user_id' => '0001',
            'merchant_user_type' => 'BUSINESS_EMPLOYEE',
            'scene_code' => 'SATF_FUND_BOOK',
            'ext_info' => ['agreement_no' => '20225310838697921224']
        ], true));
        return $this->request($request);
    }


    public function query()
    {
        //{"alipay_fund_accountbook_query_response":{"code":"10000","msg":"Success","account_book_id":"2088610021182085","available_amount":"0.00","ext_card_info":{"bank_acc_name":"支付宝（中国）网络技术有限公司","card_bank":"支付机构备付金集中存管账户","card_branch":"支付宝-备付金账户","card_deposit":"991290000015","card_location":"上海市-上海市","card_no":"2088880800281045680","status":"A"}},"alipay_cert_sn":"af4413c2e7da2680854783d0b5128cde","sign":"tstSfZWbpBdZ7iQ9h4weg8YzxE6fS79F7avAS2tx6lI23ehgGPHHhNItH4UA5ERvAYVti/MfforlJtO9cNZUx8an12HZBJL/eAsgB5xjFsN0uYg95xqXB5/ovKeJQUHVGmO6mzuDyrWoTxLBRU0MgQ0n0iHSQlCVZzgvoMvY4KObk0QSNbCzqJNUFFHLiLlEnWCvPQfcwDo8AVgK6XNgFobJXSEhpveB0W+vV6mMqY247Q6pxh14U7zEFi9F19JsQLMh51viMx4xs2Ij0kOJBBUkw3A+/dRrv1RehEiz1YDApNUPnUPHzU0v4iYsgAtIxw6SprpoXLypKiQomkmh1A=="}
        $request = new AccountQueryRequest();
        $request->setBizContent(json_encode([
            'account_book_id' => '2088610021182085',
            'scene_code' => 'SATF_FUND_BOOK',
            'ext_info' => ['agreement_no' => '20225310838697921224']
        ], true));
        return $this->request($request);
    }


    public function recharge()
    {

        $request = new AccountBookRechargeRequest();


        $request->setBizContent(json_encode([
            'out_biz_no' => '202205100001',
            'trans_amount' => 1,
            'product_code' => 'FUND_ACCOUNT_BOOK',
            'biz_scene' => 'SATF_DEPOSIT',
            'time_expire' => '2022-05-13 18:00',
            'payee_info' => ['identity_type' => 'ACCOUNT_BOOK_ID', 'identity' => '2088610021182085', 'ext_info' => '{"agreement_no":"20225310838697921224"}'],
        ], true));


        return $this->pageRequest($request);

    }


    public function rechargeQuery()
    {
        //{"alipay_fund_trans_common_query_response":{"code":"10000","msg":"Success","order_id":"20220510110075000006240079066012","out_biz_no":"202205100001","pay_date":"2022-05-10 17:43:44","pay_fund_order_id":"20220510110075001506240099225821","status":"SUCCESS","trans_amount":"1.00"},"alipay_cert_sn":"af4413c2e7da2680854783d0b5128cde","sign":"hy7lga3cuLPcvO40H/LZHd/nc5j7QhbxoOx8VpyiOnJ97joaQaU14IdMBXyY0TV/kn6YF72YmPo8SSN30szeJEtEK91+Fdk82J0a10mrbbcunPTz1YJ9JAj0OZIb+Jx/aNqXe2f0236EELaxMWc9Mv4jWwZi4ok8j6DdFkq88dSkpRpK73s4K7N9uSKQvuMIaQ6F2wCTSBBUcH2wREYLCdUFXbevLe9+e0nMr5D61ZQCGaxnzrbwlLjfhdzOuVxzn7F7d1bY8Bo7ADs9nrUpDSjgW31rmQzWlceV0TV7L9cPO4OBU+v4KBEK3E/eFTEjZNAEaG3vbVJ/k3neHbMVKg=="}
        $request = new AccountBookRechargeQueryRequest();
        $request->setBizContent(json_encode([
            'out_biz_no' => '202205100001',
            'product_code' => 'FUND_ACCOUNT_BOOK',
            'biz_scene' => 'SATF_DEPOSIT',
        ], true));

        return $this->request($request);
    }


    public function transfer()
    {
        $request = new AlipayFundTransUniTransferRequest();

        //{"alipay_fund_trans_uni_transfer_response":{"code":"10000","msg":"Success","order_id":"20220510110070000006080053943178","out_biz_no":"202205100002","pay_fund_order_id":"20220510110070001506080020635350","status":"SUCCESS","trans_date":"2022-05-10 17:57:52"},"alipay_cert_sn":"af4413c2e7da2680854783d0b5128cde","sign":"NBRFfqeY5IOeIomITw1mTLl4v2i38QA6jDOz2WwPn7JJbKS1dofFR7Q16iH7Jr7P7HnWokZ3VX9S3O7OzHNQUMi0e87A8v8a0MosiIOt3ytjd6+HfEYGDzAW/xA8kfg9QDNS7SrioR0Gc+MKSG6DLXKiyYkPgNfrEJjD4E6aDZcHEsmamRYnrjZS1E+mqEnfFsxFk8BJhWkcvkCC84/KLz66d8gsSOiK9YDWVac7UatmHqFopog5WqYsRlfaosiWZgZMLmAR8NLnE/zInjqK9M+JqcTohBkoA14n13RNKkm+e0shqDsTHcdUe8DUvoWHQ6oLF6OQ8qBYxI7sQHwdvg=="}
        $request->setBizContent(json_encode([
            'out_biz_no' => '202207050001',
            'trans_amount' => '0.2',
            'product_code' => 'SINGLE_TRANSFER_NO_PWD',
            'biz_scene' => 'ENTRUST_TRANSFER',
            'business_params' => '{"payer_show_name_use_alias":"true"}',
//            'payee_info' => [
//                'identity' => 'bangbuhexinwangluo@hxinyun.com',
//                'identity_type' => 'ALIPAY_LOGON_ID',
//                'name' => '蚌埠合薪网络科技有限公司',
//            ],
            'payee_info' => [
                'identity' => '18255382945',
                'identity_type' => 'ALIPAY_LOGON_ID',
                'name' => '许亚涛',
            ],


            'payer_info' => [//付款方
                'identity' => '2088610021182085',
                'identity_type' => 'ACCOUNT_BOOK_ID',
                'ext_info' => '{"agreement_no":"20225310838697921224"}',
            ],
        ], true));

        return $this->request($request);
    }

    public function subscribe()
    {
        $request = new AccountBookNotifySubscribe();
        $request->setBizContent(json_encode([
            'product_code' => 'SATF_FUND_BOOK',
            'biz_scene' => 'DEFAULT',
            'account_book_id' => '2088410029091765',
            'agreement_no' => '20215827781062648224'
        ], true));
        return $this->request($request);
    }


    public function sign()
    {
        $request = new AccountBookSignRequest();
        $request->setBizContent(json_encode([
            'personal_product_code' => 'FUND_SAFT_SIGN_WITHHOLDING_P',
            'sign_scene' => 'INDUSTRY|SATF_ACC',
            'access_params' => ["channel" => "QRCODE"],
            'product_code' => 'FUND_SAFT_SIGN_WITHHOLDING',
            'external_agreement_no' => '202205100001',
            'third_party_type' => 'PARTNER'
        ], true));
        return $this->pageRequest($request, 'get');
    }

    public function querySign()
    {
        $request = new AccountBookQueryRequest();

        //{"alipay_user_agreement_query_response":{"code":"10000","msg":"Success","agreement_no":"20225310838697921224","alipay_logon_id":"zkh***@hxinyun.com","external_agreement_no":"202205100001","invalid_time":"2115-02-01 00:00:00","personal_product_code":"FUND_SAFT_SIGN_WITHHOLDING_P","pricipal_type":"CARD","principal_id":"2088241908314244","sign_scene":"INDUSTRY|SATF_ACC","sign_time":"2022-05-10 17:34:27","status":"NORMAL","third_party_type":"PARTNER","valid_time":"2022-05-10 17:34:27"},"alipay_cert_sn":"af4413c2e7da2680854783d0b5128cde","sign":"tQ3hvxqee6ek128enLZ/jWIGFFvRgw+DhF/4lbqxKPLChdDDCn8fxVNa+HeF5TSBTPGWiwTFzxRo4KDUOeFzOvkaO0YD6NriKylyWQEwX1ZrGDzH5eAlaQDZbhgeU4UwsOxKU9O0PcPw5z64+DYFhl9lZpKkr8Bnkv6sf+5nUZudgngtRVM+T1jQGJoAUGxYRVfS/vXnamdCSGnxwf/h1E8K4cJNay4r8qhT9+TYOk8pP/iHbtQObpsq0W+cu9LwFJOwEZDG5h68pnwpu5dHMY1QaML/gNN+UCrT9a3klWNBG/h35PKJLrJIOwfMkUesRiIpL63rLmZb7tvfm3Wgiw=="}
        $request->setBizContent(json_encode([
            'personal_product_code' => 'FUND_SAFT_SIGN_WITHHOLDING_P',
            'sign_scene' => 'INDUSTRY|SATF_ACC',
            'product_code' => 'FUND_SAFT_SIGN_WITHHOLDING',
            'external_agreement_no' => '202205100001',
        ], true));
        return $this->request($request);
    }

}
